package com.itheima.ydd.controller;

import com.itheima.ydd.entity.Result;
import com.itheima.ydd.entity.YddLink;
import com.itheima.ydd.service.YddLinkService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@RequestMapping("/ydd_link")
public class YddLinkController {
    @Autowired
    private YddLinkService yddLinkService;

    /**
     * 分页查询友情链接
     *
     * @param type
     * @param page
     * @param limit
     * @return
     */
    @GetMapping("/list")
    public ResponseEntity<Result> findAll(Integer type, Integer page, Integer limit) {
        return yddLinkService.findAll(type, page, limit);
    }

    /**
     * 新增友情链接功能
     *
     * @param yddLink
     * @return
     */
    @PostMapping("/add")
    public ResponseEntity<Result> add(@RequestBody YddLink yddLink) {
        return yddLinkService.add(yddLink);
    }

    /**
     * 根据id查询数据
     *
     * @param id
     * @return
     */
    @GetMapping("/rowInfo")
    public ResponseEntity<Result> findById(Integer id) {
        return yddLinkService.findById(id);
    }

    /**
     * 修改功能实现
     * @param yddLink
     * @return
     */
    @PostMapping("/update")
    public ResponseEntity<Result> updateById(@RequestBody YddLink yddLink) {
        return yddLinkService.updateLink(yddLink);
    }

    @GetMapping("/del")
    public ResponseEntity<Result> delete(Integer id){
        return yddLinkService.delete(id);
    }
}
